package com.bawei.andfix;

import android.content.Context;

import com.alipay.euler.andfix.patch.PatchManager;

import java.io.IOException;

/**
 * @Author : yaotianxue
 * @Time : On 2023/6/7 14:58
 * @Description : AndFixPatchManager
 */
public class AndFixPatchManager {
    private PatchManager patchManager;
    private AndFixPatchManager(){}
    private static AndFixPatchManager mAndFixPatchManager;
    public static AndFixPatchManager getInstance(){
        if(mAndFixPatchManager == null){
            synchronized (AndFixPatchManager.class){
                if(mAndFixPatchManager == null){
                    mAndFixPatchManager = new AndFixPatchManager();
                }
            }
        }
        return mAndFixPatchManager;
    }

    /**
     * 初始化AndFix方法
     * @param context
     */
    public void initPatch(Context context){
        patchManager = new PatchManager(context);
        patchManager.init("1");//current version
        patchManager.loadPatch();
    }

    /**
     * 加载patch文件
     */
    public void addPatch(String path){
        if(patchManager != null){
            try {
                patchManager.addPatch(path);
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }



}
